import DataItemModel from "../../../cfw/mvc/DataItemModel";
import { ClotheItemModelEnum } from "../../../public/GameEnumConfig";
import ClotheManager from "./ClotheManager";
import User from "../../db/User";
import { ItemState } from "../../../cfw/tools/Define";
import Player from "../../player/Player";
/**
* 服饰表
**/
export default class ClotheItemModel extends DataItemModel {

	static CLASS_NAME: string = 'ClotheItemModel'


	init(id, data) {
		super.init(id, data)
		this.state = User.instance().getClotheState(this.ID)
	}

	needBuy() {
		let cost: number[] = this.getCostItem()
		return cost.length > 0 && this.getState() != ItemState.GOT
	}

	setState(s) {
		super.setState(s)
		User.instance().setClotheState(this.ID, s)
	}
	getOpenLevel() {
		let num = this.data[ClotheItemModelEnum.adge]
		return num ? num : 0
	}
	
	isOpen() {
		return Player.instance().getLevel() >= this.getOpenLevel()
	}
	// icon
	getIcon() {
		let typeModel = ClotheManager.instance().getClotheType(this.getClotheType());
		return 'texture/' + typeModel.getFolderName() + '/' + this.data[ClotheItemModelEnum.icon]
	}
	// 图标缩放
	getScale() {
		return this.data[ClotheItemModelEnum.scale]
	}


	// 眼镜
	getMask() {
		let res = this.data[ClotheItemModelEnum.mask]
		let typeModel = ClotheManager.instance().getClotheType(this.getClotheType());
		if (res) {
			return 'texture/' + typeModel.getFolderName() + '/' + res
		} else {
			return 'texture/' + typeModel.getFolderName() + '/' + this.data[ClotheItemModelEnum.icon]
		}
	}
	// 消费道具
	getCostItem() {
		return this.data[ClotheItemModelEnum.costItem]
	}
	// 衣物类型
	getClotheType() {
		let type = this.data[ClotheItemModelEnum.clotheType]
		return type;
	}
	// 属于哪个衣架
	getColumnID() {
		return this.data[ClotheItemModelEnum.columnID]
	}


	use() {
		User.instance().setTypeData(this.getClotheType(), this.getID())
		let oppType = this.getOppType();
		if (oppType > 0) {
			User.instance().setTypeData(oppType, 0)
		}
	}

	unUse() {
		User.instance().setTypeData(this.getClotheType(), 0)
	}

	getOppType() {
		let typeModel = ClotheManager.instance().getClotheType(this.getClotheType());
		return typeModel.getOppType()
	}

	canDel() {
		let typeModel = ClotheManager.instance().getClotheType(this.getClotheType());
		return typeModel.getCanDel() == 1;
	}

	// 偏移量
	getOffset() {
		return this.data[ClotheItemModelEnum.offset]
	}
}